package com.atguigu.boot.event;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;

/**
 * 4、自定义事件监听器并注册事件监听器
 * Spring Boot进行事件监听有四种方式：
 *
 * 手工向ApplicationContext中添加监听器
 * 在application.properties中配置监听器
 * 将监听器装载入Spring容器
 * 通过@EventListener注解实现事件监听
 *
 * @author lihj
 * @version 1.0.0
 * @title CustomListener
 * @description <TODO description class purpose>
 * @date 2023/7/11
 */
public class CustomListener implements ApplicationListener<CustomEvent> {
    private Logger logger = LoggerFactory.getLogger(CustomListener.class);
    @Override
    public void onApplicationEvent(CustomEvent customEvent) {
        //这里不做处理，只对消息进行透传打印，实际情况，
        //可以根据项目进行逻辑进行处理
        logger.info("CustomListener Spring 监听：==> onApplicationEvent method : {}", customEvent.getMsg());
        customEvent.printMsg(customEvent.getMsg());
    }
}
